<?php
/**
 * Created by PhpStorm.
 * User: geyouwen
 * Date: 16/8/20
 * Time: 下午9:10
 */

namespace Superadmin\Controller;


class LevelController extends BaseController
{

    private  $mod;
    public function __construct()
    {
        parent::__construct();
        $this->mod = D('level');
    }

    public function index()
    {

        $list = M('level')->order('score asc')->select();
        $this->assign('list', $list);
        $this->display();
    }



    public function add()
    {
        if(IS_AJAX)
        {
            $this->mod->create();
            if(!($this->mod->ordid))  $this->mod->ordid = 255;
            $this->mod->add();
            $back = array(
                'status' => 1,
                'msg'    => L('operation_success')
            );
            $this->ajaxReturn($back);
        }
        $this->display();
    }

    public function edit()
    {
        if(IS_AJAX)
        {
            $id = I('id');
            $this->mod->create();
            $this->mod->where(array('id' => $id))->save();
            $back = array(
                'status' => 1,
                'msg'    => L('operation_success')
            );
            $this->ajaxReturn($back);
        }
        $id = I('id');
        $info = $this->mod->find($id);
        $this->assign('info', $info);
        $this->display();
    }

    public function delete()
    {
        if(IS_AJAX){
            $id = I('get.id');
            $this->mod->where(array('id' => $id))->delete();
            $back = array(
                'status' => 1,
                'msg'    => L('operation_success')
            );
            $this->ajaxReturn($back);
        }

    }


}